<?php

namespace app\beautiful\model\appointment;

use app\beautiful\model\member\MemberModel;

use app\beautiful\model\project\ProjectModel;

use app\common\model\CommonModel;



class AppointmentModel extends CommonModel{

    protected  $name = 'beautiful_appointment';

    protected  $pk   = 'appointment_id';



    public function project()

    {

        return $this->hasOne(ProjectModel::class,'project_id','project_id');

    }



    public function member()

    {

        return $this->hasOne(MemberModel::class,'member_id','member_id');

    }



    public function technician()

    {

        return $this->hasOne(TechnicianModel::class,'technician_id','technician_id');

    }







    public function getStatusMeansAttr($value,$data)

    {

        $status_means=[

            1=>'待确定',

            4=>'待到店',

            8=>'已完成',

            -1=>'已取消',

        ];

        return $status_means[$data['status']] ?? '';

    }



    public function getOperateTypeMeansAttr($value,$data)

    {

        $operate_type_means=[

            0=>'用户',

            1=>'员工',

            2=>'管理员'

        ];



        return $operate_type_means[$data['operate_type']] ?? '';

    }



    public function getArrivalTimeFormatAttr($value,$data)

    {



        return $data['arrival_time'] > 0 ? date('Y-m-d H:i:s',$data['arrival_time']) : '-';

    }



    public function getCancelTimeFormatAttr($value,$data)

    {



        return $data['cancel_time'] > 0 ? date('Y-m-d H:i:s',$data['cancel_time']) : '-';

    }



    public function getCancelTimeSmallFormatAttr($value,$data)

    {



        return $data['cancel_time'] > 0 ? date('m月d日',$data['cancel_time']) : '-';

    }



    public function getAppointmentTimeFormatAttr($value,$data)

    {

        $weekarray=array("日","一","二","三","四","五","六");

        if(false === $day_unix = strtotime($data['day'].' 00:00:00')) return '-';

        return date("m月d日",$day_unix).'(周'.$weekarray[date('w',$day_unix)].')';

    }





}

